<?php

class core{
    public function __construct()
    {

    }
    /**
     * @name 日志记录
     * @param array data 日志数据
     */
    public static function logger($data) {
        if(ISDEBUG){
            $text = '';
            $data['TIME'] = date('Y-m-d H:i:s');
            $data['URI'] = $_SERVER['REQUEST_URI'];
            foreach ($data as $k => $v) $text .= '['.$k.']: '.$v."<br />";
            $text .= "<br />";
            echo $text;
            exit;
        }else{
            $text = '';
            $data['TIME'] = date('Y-m-d H:i:s');
            $data['URI'] = $_SERVER['REQUEST_URI'];
            foreach ($data as $k => $v) $text .= '['.$k.']: '.$v."\r\n";
            $text .= "\r\n";
            file_put_contents(PATH_ROOT.'/data/log/'.date('Y.m.d').'.txt', $text, FILE_APPEND);
        }
    }

    /**
     * @name 错误捕获
     * @param int type 错误类型
     * @param string message 错误信息
     * @param string file 错误文件
     * @param string line 错误行号
     */
    public static function error_handler($type, $message, $file, $line) {
        $data = array(
            'MSG'  => $message,
            'FILE' => $file,
            'LINE' => $line,
        );
        self::logger($data);
        if ($type !== E_WARNING && $type !== E_NOTICE && $type !== E_STRICT) self::error($message);
    }
}